//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
using System;
using System.Diagnostics.Contracts;
using System.IO;
using System.Text;
namespace LargoCommon.Midi {
/// An unknown meta event message.
[Serializable]
public sealed class MetaUnknown : MetaEvent {
#region Fields
///
/// Event data.
///
private byte[] data;
#endregion
#region Constructors
/// Initializes a new instance of the MetaUnknown class.
/// The amount of time before this event.
/// The event ID for this meta event.
/// The data associated with the event.
public MetaUnknown(long deltaTime, byte givenMetaEventId, byte[] givenData) :
base(deltaTime, givenMetaEventId) {
this.SetData(givenData);
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
if (this.GetData() != null) {
sb.Append("\t");
}
sb.Append(MidiEvent.DataToString(this.GetData()));
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Event data
MidiEvent.WriteVariableLength(outputStream, this.GetData() != null ? this.GetData().Length : 0);
if (this.GetData() != null) {
outputStream.Write(this.GetData(), 0, this.GetData().Length);
}
}
#endregion
#region Data
///
/// Gets or sets the data for the event.
///
/// Returns value.
/// General musical property.
private byte[] GetData() {
Contract.Ensures(Contract.Result() != null);
if (this.data == null) {
throw new InvalidOperationException("Midi event data can not be null.");
}
return this.data;
}
///
/// Sets the data.
///
/// The value.
private void SetData(byte[] value) {
this.data = value;
}
#endregion
}
}